Component({
  properties: {
    value: {
      type: Number,
      value: 0
    },
    min: {
      type: Number,
      value: 0
    },
    max: {
      type: Number,
      value: 99
    }
  },

  methods: {
    onMinus() {
      if (this.data.value > this.data.min) {
        this.triggerEvent('sub', {
          value: this.data.value - 1
        });
      }
    },

    onPlus() {
      if (this.data.value < this.data.max) {
        this.triggerEvent('add', {
          value: this.data.value + 1
        });
      }
    },

    onInput(e) {
      let value = parseInt(e.detail.value) || 0;

      if (value < this.data.min) value = this.data.min;
      if (value > this.data.max) value = this.data.max;

      this.setData({
        value
      });
      this.triggerEvent('change', {
        value
      });
    },

    onBlur(e) {
      let value = parseInt(e.detail.value) || 0;

      if (value < this.data.min) value = this.data.min;
      if (value > this.data.max) value = this.data.max;

      this.setData({
        value
      });
      this.triggerEvent('change', {
        value
      });
    }
  }
})